package com.fr.lintcode;

import org.junit.Test;

public class Q78 {
	public String longestCommonPrefix(String[] strs) {
		if (strs == null || strs.length == 0){
			return "";
		}
		if (strs.length ==1){
			return strs[0];
		}
		String s = strs[0];
		int i = 0;
		a:while(i < s.length()){
			char c = s.charAt(i);
			for(String str : strs){
				if (str.length() <= i){
					break a;
				}
				if (c != str.charAt(i)){
					break a;
				}
			}
			i ++;
		}
		return s.substring(0,i);
    }
	
	@Test
	public void TestA(){
		String [] strs = {"abc","abcd","","ab","ac"};
		System.out.println(longestCommonPrefix( strs));
	}

}
